package com.a3dweijing.wetouch2.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;


import com.a3dweijing.wetouch2.R;
import com.a3dweijing.wetouch2.Util.ImageLoaderUtil;
import com.a3dweijing.wetouch2.bean.ExpoonVideo;
import com.a3dweijing.wetouch2.callback.PartitionOnclick;

import java.util.List;

/**
 * Created by yxd on 2017/11/5.
 */

public class PartitionRecItemAdapter extends RecyclerView.Adapter<PartitionRecItemAdapter.MyViewHolder> {
    List<ExpoonVideo> videos;
    PartitionOnclick onclick;

    public PartitionRecItemAdapter(List<ExpoonVideo> videos, PartitionOnclick onclick) {
        this.videos = videos;
        this.onclick=onclick;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new MyViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_partition_botton_video,parent,false));
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, final int position) {
        holder.name.setText(videos.get(position).getVideoName());
        holder.describe.setText(videos.get(position).getVideoDescribe());
        ImageLoaderUtil.getLoader().loadImg4(videos.get(position).getVideoShowImg(),holder.pic);
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onclick!=null){
                    onclick.videoclick(position,videos.get(position));
                }
            }
        });

    }

    @Override
    public int getItemCount() {
        if (videos!=null && videos.size()>0){
            return videos.size();
        }
        return 0;
    }

    class MyViewHolder extends RecyclerView.ViewHolder{
        private ImageView pic;
        private TextView name;
        private TextView describe;
        public MyViewHolder(View itemView) {
            super(itemView);
            pic= (ImageView) itemView.findViewById(R.id.partition_video_pic);
            name= (TextView) itemView.findViewById(R.id.partition_video_name);
            describe= (TextView) itemView.findViewById(R.id.partition_video_describe);
        }
    }
}
